package work.mediway.mdm.biz.vo.dict;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import cn.hutool.core.collection.CollUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2020/12/17
 */
@Data
@ApiModel
public class DictFieldVO implements RowMapper<DictFieldVO> {

    @ApiModelProperty(value = "字段名称")
    private String fieldCode;

    @ApiModelProperty(value = "字段描述")
    private String fieldDesc;

    @ApiModelProperty(value = "表名")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String tableName;

    @ApiModelProperty(value = "Code")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String relCode;

    @ApiModelProperty(value = "查看")
    private String ssBrowse;

    @ApiModelProperty(value = "编辑")
    private String ssEdit;

    @ApiModelProperty(value = "外键字段")
    private String fkColumnName;

    @ApiModelProperty(value = "外键表名")
    private String fkTableName;

    @ApiModelProperty(value = "是否为当前表字段")
    private String currTable;

    @ApiModelProperty(value = "是否为主键")
    private String primaryKey;

    @ApiModelProperty(value = "是否必须")
    private Boolean required;

    @ApiModelProperty(value = "数据库类型")
    private String sqlType;

    @ApiModelProperty(value = "列长度")
    private String columnSize;

    @ApiModelProperty(value = "是否自增")
    private String isAutoIncrement;

    @ApiModelProperty(value = "可用值")
    private List<String> availableValues = CollUtil.newArrayList();

    @ApiModelProperty(value = "可用值")
    private List<String> availableValuesDesc = CollUtil.newArrayList();

    @ApiModelProperty(value = "可用值", hidden = true)
    @JsonIgnore
    private String availableValue;

    @ApiModelProperty(value = "初始值")
    private String initialExpression;

    @ApiModelProperty(value = "ssOrder")
    private String ssOrder;

    @Override
    public DictFieldVO mapRow(ResultSet rs, int rowNum) throws SQLException {
        DictFieldVO vo = new DictFieldVO();
        vo.setFieldCode(rs.getString("fieldCode"));
        vo.setFieldDesc(rs.getString("fieldDesc"));
        vo.setRequired(rs.getBoolean("required"));
        vo.setSqlType(rs.getString("sqlType"));
        vo.setAvailableValue(rs.getString("availableValue"));
        vo.setInitialExpression(rs.getString("initialExpression"));
        return vo;
    }
}
